<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <script src="js/swiper-4.2.6.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="css/swiper-4.2.6.min.css"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/font.js"></script>
    <link rel="stylesheet" href="css/base.css">
    <script src="js/public.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="css/ui.css">
    <title></title>
    <!-- 个人中心-费用中心-充值 -->
    <style>
    </style>
</head>
<body>
<div class="scroll-content2 my-costcenter-recharge" style="overflow:auto;background: #F5F5F5;">
    <div class="top-public">
        <span class="public-center">充值</span>
        <img src="images/left_icon.png" alt="" class="public-left">
    </div>
    <div class="recharge-top">
        <div class="recharge-top-text">充值金额</div>
        <div class="show-price">
            <div class="show-price-center">
                <input type="text" id="money" value="0.00">
                <span class="yuan">元</span>
            </div>
        </div>
    </div>
    <div class="choice-price">
        <ul>
            <li class="active" onclick="xzje(this)">
                <p class="price">10000</p>
                <p>元</p>
            </li>
            <li onclick="xzje(this)">
                <p class="price">50000</p>
                <p>元</p>
            </li>
            <li onclick="xzje(this)">
                <p class="price">100000</p>
                <p>元</p>
            </li>
        </ul>
    </div>
    <div class="payment-method">
        <div class="payment-method-title">支付方式</div>
        <div class="payment-method-list">
            <ul id="payCode">
                <!--<li style="background: #fff url(images/confirm-zfb.png) no-repeat 4% center;background-size:0.22rem 0.22rem;">支付宝-->
                    <!--<div class="choice-btn" id="aliPay" onclick="xz(this)"></div>-->
                <!--</li>-->
                <li style="background: #fff url(images/confirm-wx.png) no-repeat 4% center;background-size:0.21rem 0.17rem;">微信支付
                    <div class="choice-btn active1" id="wxPay" onclick="xz(this)"></div>
                </li>
                <!-- <li style="background: #fff url(images/confirm-ye.png) no-repeat 4% center;background-size:0.22rem 0.22rem;">余额支付
                    <div class="choice-btn" onclick="xz(this)"></div>
                </li> -->
            </ul>
        </div>
    </div>
    <div class="sub-btn" onclick="recharge()">充值</div>
</div>
</body>
<script>
$('.public-left').click(function(){
    window.history.go(-1);
})
// 选择金额
// 用户既可以选择指定的三个金额也可以自由填写金额
function xzje(obj){
    $('.choice-btn').removeClass('active');
    $(obj).addClass('active').siblings().removeClass('active');
}

// 选择支付方式
function xz(obj){
    $('.choice-btn').removeClass('active1');
    $(obj).addClass('active1').closest("li").siblings().find(".choice-btn").removeClass('active1');
}
</script>
<script>
    $(function(){
        //验证是否登陆
        var user_id = sessionStorage.getItem('userId');
        if (user_id == null) {
            alert("请您先登录！");
            window.location.href = 'login.html';
        }
    });
    
    function recharge() {
        var user_id = sessionStorage.getItem('userId');
        var money = $('#money').val();
        var price = $('.choice-price .active .price').html();
        if (money>0) {
            var subMoney = money;
        } else {
            subMoney = price;
        }
        var pay_code = $('#payCode .active1')[0].id; //支付方式
        if (pay_code == 'aliPay') {
            alert ('支付宝功能暂未开放,请选择其他支付方式！');
            return false;
        }
        $.ajax({
            url: url() + 'api/users/rechargeBalance',    //请求的url地址
            dataType: "JSON",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            type: "POST",   //请求方式
            data:{
                user_id:user_id,
                subMoney:subMoney, //充值价格
                pay_code:pay_code, //支付方式
            },
            success: function (data) {
                console.log(data);
                //请求成功时处理
                if(data.status==1){
                    var out_trade_no = data.result.order_sn;
                    var account = data.result.account;
                    window.location.href=`http://vip.bndvip.com/api/Pay/wxPay?out_trade_no=${out_trade_no}&total_fee=${account}&total_fee2=2`;
                } else {
                    console.log('充值失败！');
                }
            }
        });

    }
</script>
</html> 






